package gui.polish;

import gui.mpm.MPMFrame;

import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import org.apache.log4j.spi.LocationInfo;

import clients.RPCClient;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.awt.SystemColor;
import javax.swing.UIManager;
/**
 * 
 * @author adam
 *This frame works with the MyInfoPanel , initializes it .
 */
public class MyInfoFrame extends JFrame {
	private MyInfoPanel myInfoPanel;
	private MyInfoFrame myInfoFrame;
	private ArrayList respond ;
	private PolishFrame myFrame;
	private RPCClient myRPCClient;
	private DefaultTableModel model;
	/**
	 * Constructor . 
	 * @param frame		receives the main frame "polish frame" 
	 * @param a	- jar contents
	 * @param selectedColumnIndex
	 * @param selectedRowIndex
	 * @param myPolishPane
	 * @param jarID
	 * @param endDate
	 */
	public MyInfoFrame(PolishFrame frame,ArrayList a,int selectedColumnIndex,int selectedRowIndex,PolishPanel myPolishPane,String jarID,String endDate) {
		myFrame=frame;
		ArrayList<Object>message = new ArrayList<>();
		ArrayList<Object>respond1 = new ArrayList<>();
		setIconImage(Toolkit.getDefaultToolkit().getImage(MPMFrame.class.getResource("/graphics/Spearhead.png")));
    	setTitle("ח.נ.י.ת");
		respond=a;
		getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		myInfoFrame=this;
		myInfoPanel = new MyInfoPanel(myInfoFrame,respond,selectedColumnIndex,selectedRowIndex,myPolishPane,jarID,endDate);
	
		try{
			myRPCClient = new RPCClient();
			message.add("updateGuiCommentsFromPolish");
			message.add(jarID);
			model = (DefaultTableModel) myInfoPanel.table.getModel();
			String orderID = model.getValueAt(0, 0).toString();
			message.add(orderID);
			respond1 = myRPCClient.call(message);
			if(respond1.get(1).toString().equalsIgnoreCase("valid"))
			{
				myInfoPanel.textAreaComments.setText(respond1.get(2).toString());
			}
			else{
				//something is wrong
			}
		}
		catch(Exception e)
		{
			//e.printStackTrace();
		}
		myInfoFrame.setContentPane(myInfoPanel);
		myInfoFrame.setMinimumSize(new Dimension(550,300));
		myInfoFrame.pack();
		//Gets the mother frame location and sets the new frame in it's bounds .
		myInfoFrame.setLocation(frame.getX()+50,myFrame.getY()+50);
		myInfoFrame.setVisible(true);
	}

}
